<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <link rel="shortcut icon" href="images/favicon.ico"/>
        <title>JForum :: #{resourcesController.extractResource('FILESHARE')}</title>
    </h:head>
    <h:body style="background-color: #111111">
        
       <div id="header">
		<ui:insert name="header" >
			<ui:include src="header.xhtml" />
		</ui:insert>
       </div>
        
       <center>
      
              
              <p:panel header="JForum :: #{resourcesController.extractResource('FILESHARE')}" 
                       style="width:790px">
                  <div align="center">
                      <p:growl id="messageGrowl" showDetail="true"/>
                          
                        <p:panel header="#{resourcesController.extractResource('UPLOAD_DOWNLOAD')}"
                                 style="width:750px">   
                           
                                <p:dataTable value="#{fileDownloadBean.fileList}"
                                             var="fileEntry"
                                             paginator="true" 
                                             rows="10"
                                             id="fileTable">
                                      
                                    <f:facet name="header">
                                        <h:form enctype="multipart/form-data">
                                             <p:fileUpload fileUploadListener="#{fileUploadBean.handleFileUpload}"
                                                            cancelLabel="#{resourcesController.extractResource('ABORT')}"
                                                            uploadLabel="#{resourcesController.extractResource('UPLOAD')}"
                                                            label="#{resourcesController.extractResource('SELECT_FILE')}"
                                                            update="@all"
                                                            mode="advanced"
                                                            sizeLimit="5000000"
                                                            disabled="#{authorizationBean.user == null}"
                                                            invalidSizeMessage="#{resourcesController.extractResource('NOTIFY_FILESHARE')}"/>
                                             <h:outputText value="#{fileUploadBean.uploadStatusMessage}"/>
                                        </h:form>
                                    </f:facet>
                                    
                                    <p:column>
                                        <f:facet name="header">
                                           <h:form> 
                                            <p:commandButton value="#{resourcesController.extractResource('REFRESH_FILES')}"
                                                              action="/fileshare.xhtml?faces-redirect=true"/>
                                           </h:form>
                                        </f:facet>
                                        
                                        <c:if test="#{authorizationBean.user == null || authorizationBean.user.gid == 3}">
                                          <h:form>
                                                <p:poll interval="5" 
                                                        listener="#{fileDownloadBean.reloadFileList()}" />
                                                <center>
                                                    <p:commandButton value="#{fileEntry}"
                                                                     ajax="false" 
                                                                     disabled="#{authorizationBean.user == null}"
                                                                     style="width: 560px; left: 20px; background: url('#{fileDownloadBean.getIcon(fileEntry)}') no-repeat left top">
                                                        <p:fileDownload value="#{fileDownloadBean.getFile(fileEntry)}"/>
                                                    </p:commandButton>
                                                </center>
                                          </h:form>
                                        </c:if>
                                        
                                        <c:if test="#{authorizationBean.user.gid le 2}">
                                          <h:form>
                                            <p:poll interval="5" 
                                                    listener="#{fileDownloadBean.reloadFileList()}" />
                                            
                                            <p:commandButton value="#{fileEntry}"
                                                             ajax="false" 
                                                             disabled="false"  
                                                             style="width:560px; left: 20px; float:left; background: url('#{fileDownloadBean.getIcon(fileEntry)}') no-repeat left top">
                                                
                                                <p:fileDownload value="#{fileDownloadBean.getFile(fileEntry)}"/>
                                            </p:commandButton>
                                          </h:form>
                                          <h:form> 
                                            <p:commandButton value="#{resourcesController.extractResource('REMOVE')}"  
                                                             async="true"
                                                             ajax="false"
                                                             action="#{fileDownloadBean.removeFile(fileEntry)}"/>
                                            </h:form> 
                                        </c:if>
                                    </p:column>
                                </p:dataTable>
                                
                        </p:panel>
                 </div>
            </p:panel>
        </center> 
        <ui:insert name="header" >
			<ui:include src="footer.xhtml" />
        </ui:insert>
    </h:body>
</html>

